<?php if (!empty($data)) : ?>
<div class="hastable">
    <table class="items">
        <colgroup>
            <col width="50">
            <col>
            <col width="65">
            <col width="100">
            <col width="108">
        </colgroup>
        <thead class="table-header">
            <tr class="headings">
                <th><?php echo $model->getAttributeLabel('order'); ?></th>
                <th><?php echo $model->getAttributeLabel('title'); ?></th>
                <th><?php echo $model->getAttributeLabel('activated_flag'); ?></th>
                <th><?php echo $model->getAttributeLabel('sort'); ?></th>
                <th>&nbsp;</th>
            </tr>
        </thead>
        <tbody>
            <?php
            $trType = array('even', 'odd');
            $maxRepeat = count($data);
            $tagToggle = '<td>
                <span ref="%s"
                      class="haveIconHover ui-icon ui-icon-circle-%s callAjax">
                </span></td>';
            
            $tagFirst = '<a href="javascript:void(0)" class="order_link">
                <span ref="%s"
                      class="callAjax haveIconHover ui-icon ui-icon-arrowthickstop-1-n float-left">
                </span></a>';
            $tagUp = '<a href="javascript:void(0)" class="order_link">
                <span ref="%s"
                      class="callAjax haveIconHover ui-icon ui-icon-arrowthick-1-n float-left haveIconHover">
                </span></a>';
            $tagDown = '<a href="javascript:void(0)" class="order_link">
                <span ref="%s"
                      class="callAjax haveIconHover ui-icon ui-icon-arrowthick-1-s float-left haveIconHover">
                </span></a>';
            $tagLast = '<a href="javascript:void(0)" class="order_link">
                <span ref="%s" style="margin-right:0;"
                      class="callAjax haveIconHover ui-icon ui-icon-arrowthickstop-1-s float-left">
                </span></a>';
            
            $tagTool = '<ul class="ui-widget ui-helper-clearfix" id="icons">
                <a href="%s" title="'. Yii::t('DadminModule.app', 'update') .'">
                    <li class="ui-state-default ui-corner-all">
                        <span class="ui-icon ui-icon-wrench"></span>
                    </li>
                </a>
                <span style="margin-top:5px;cursor:default;"
                      class="ui-icon ui-icon-grip-dotted-vertical">
                </span>
                <a href="%s" class="callDelete" title="'. Yii::t('DadminModule.app', 'delete') .'">
                    <li class="ui-state-default ui-corner-all">
                        <span class="ui-icon ui-icon-trash"></span>
                    </li>
                </a>
            </ul>';
            
            for ($i=1; $i<=$maxRepeat; $i++) {
                $tr = $i % 2;
                
                echo CHtml::openTag('tr', array('class' => $trType[$tr]));
                echo '<td style="text-align: center;">' . $i . '</td>';
                echo '<td>' . $data[$i]['title'] . '</td>';
                
                //acitve & preview
                $link = $this->createUrl('toggle', array('key'=>'activated_flag', 'id'=>$i));
                $icon = ($data[$i]['activated_flag']) ? 'check' : 'close';
                echo sprintf($tagToggle, $link, $icon, 'Active');
                    
                //---------- sort order ----------
                echo '<td>';
                
                if ($i != 1) {
                    $link = $this->createUrl('moveRecord', array('direct' => 'first','id' => $i));
                    echo sprintf($tagFirst, $link);
                    $link = $this->createUrl('moveRecord', array('direct' => 'down','id' => $i - 1));
                    echo sprintf($tagUp, $link);
                } else {
                    echo sprintf($tagFirst, '');
                    echo sprintf($tagUp, '');
                }
                
                if ($i != $maxRepeat) {
                    $link = $this->createUrl('moveRecord', array('direct' => 'down','id' => $i));
                    echo sprintf($tagDown, $link);
                    $link = $this->createUrl('moveRecord', array('direct' => 'last','id' => $i));
                    echo sprintf($tagLast, $link);
                } else {
                    echo sprintf($tagDown, '');
                    echo sprintf($tagLast, '');
                }
                
                echo '</td>';
                //---------- //sort order ----------
                
                //button
                echo '<td>';
                echo vsprintf($tagTool, array(
                    $this->createUrl('update', array('id'=>$i)),
                    $this->createUrl('delete', array('id'=>$i)),
                ));
                echo '</td>';
                echo CHtml::closeTag('tr');
            }
            ?>
        </tbody>
    </table>
</div>
<?php endif; ?>
<div class="clearfix"></div>